package cn.kgc.goodsmanager.service.impl;

import cn.kgc.goodsmanager.mapper.DetailMapper;
import cn.kgc.goodsmanager.pojo.Detail;
import cn.kgc.goodsmanager.pojo.DetailExample;
import cn.kgc.goodsmanager.service.DetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 郭祥伟
 */
@Service
public class DetailServiceImpl implements DetailService {
    @Resource
    DetailMapper detailMapper;
    @Override
    public PageInfo<Detail> select(Integer pageNum, Integer pageSize, Integer sortId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Detail> detailList;
        if(sortId!=0){
            DetailExample example=new DetailExample();
            DetailExample.Criteria criteria=example.createCriteria();
            criteria.andSortidEqualTo(sortId);
            detailList=detailMapper.selectByExample01(example);
        }else{
            detailList=detailMapper.selectByExample01(null);
        }
        PageInfo<Detail> pageInfo=new PageInfo<>(detailList);
        return pageInfo;
    }

    @Override
    public Integer add(Detail detail) {
        int i=detailMapper.insert(detail);
        return i;
    }

    @Override
    public Detail selectById(Integer id) {
        Detail detail=detailMapper.selectByPrimaryKey(id);
        return detail;
    }

    @Override
    public Integer update(Detail detail) {
        int i=detailMapper.updateByPrimaryKey(detail);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=detailMapper.deleteByPrimaryKey(id);
        return i;
    }
}
